package fr.umlv.m2.jee.spij.service.project;

import fr.umlv.m2.jee.spij.persistence.education.Project;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.Date;

/**
 * @author thomas magny
 * @author mathieu mazzolini
 */
@Component("projectBean")
public class DisplayProject implements Serializable {

    /**
     * Primary key.
     */
    private long id;

    /**
     * unit name
     */
    private String unitName;

    /**
     * About teaching.
     */
    private String subject;

    /**
     * Contain of Project.
     */
    private String contain;

    /**
     * Link of Project in PDF
     */
    private String linkSupport;

    /**
     * Closing date for submission.
     */
    private Date deadLineDate;

    /**
     * Closing hours for submission.
     */
    private Date deadLineHour;

    /**
     * Hour of Project's presentation.
     */
    private Date presentationHour;

    /**
     * Date of Project's presentation.
     */
    private Date presentationDate;

    /**
     * Id of linked unit.
     */
    private Long unit;

    /**
     * Weight of the review
     */
    private int weight;

    public DisplayProject() {

    }

    public DisplayProject(Project project) {
        if (project != null)
            storeData(project);
    }

    /**
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * @return the unitName
     */
    public String getUnitName() {
        return unitName;
    }

    /**
     * @param unitName the unitName to set
     */
    public void setUnitName(String unitName) {
        this.unitName = unitName;
    }

    /**
     * @return the subject
     */
    public String getSubject() {
        return subject;
    }

    /**
     * @param subject the subject to set
     */
    public void setSubject(String subject) {
        this.subject = subject;
    }

    /**
     * @return the contain
     */
    public String getContain() {
        return contain;
    }

    /**
     * @param contain the contain to set
     */
    public void setContain(String contain) {
        this.contain = contain;
    }

    /**
     * @return the linkSupport
     */
    public String getLinkSupport() {
        return linkSupport;
    }

    /**
     * @param linkSupport the linkSupport to set
     */
    public void setLinkSupport(String linkSupport) {
        this.linkSupport = linkSupport;
    }

    /**
     * @return the unit
     */
    public Long getUnit() {
        return unit;
    }

    /**
     * @param unit the unit to set
     */
    public void setUnit(Long unit) {
        this.unit = unit;
    }

    /**
     * @return the weight
     */
    public int getWeight() {
        return weight;
    }

    /**
     * @param weight the weight to set
     */
    public void setWeight(int weight) {
        this.weight = weight;
    }

    /**
     * @return the deadLineDate
     */
    public Date getDeadLineDate() {
        return new Date(deadLineDate.getTime());
    }

    /**
     * @param deadLineDate the deadLineDate to set
     */
    public void setDeadLineDate(Date deadLineDate) {
        this.deadLineDate = new Date(deadLineDate.getTime());
    }

    /**
     * @return the deadLineHour
     */
    public Date getDeadLineHour() {
        return new Date(deadLineHour.getTime());
    }

    /**
     * @param deadLineHour the deadLineHour to set
     */
    public void setDeadLineHour(Date deadLineHour) {
        this.deadLineHour = new Date(deadLineHour.getTime());
    }

    /**
     * @return the presentationHour
     */
    public Date getPresentationHour() {
        //return new Date(presentationHour.getTime());
        return presentationHour;
    }

    /**
     * @param presentationHour the presentationHour to set
     */
    public void setPresentationHour(Date presentationHour) {
        this.presentationHour = presentationHour;
    }

    /**
     * @return the presentationDate
     */
    public Date getPresentationDate() {
        //return new Date(presentationDate.getTime());
        return presentationDate;
    }

    /**
     * @param presentationDate the presentationDate to set
     */
    public void setPresentationDate(Date presentationDate) {
        this.presentationDate = presentationDate;
    }

    private void storeData(Project project) {
        if (project.getId() > 0)
            setId(project.getId());
        if (project.getSubject() != null)
            setSubject(project.getSubject());
        if (project.getContain() != null)
            setContain(project.getContain());
        if (project.getDeadLine() != null) {
            setDeadLineDate(project.getDeadLine().toDate());
            setDeadLineHour(project.getDeadLine().toDate());
        }
        if (project.getPresentation() != null) {
            setPresentationDate(project.getPresentation().toDate());
            setPresentationHour(project.getPresentation().toDate());
        }
        if (project.getLinkSupport() != null)
            setLinkSupport(project.getLinkSupport());
        if (project.getUnit() > 0)
            setUnit(project.getUnit());
        if (project.getWeight() > 0)
            setWeight(project.getWeight());
    }
}
